CFG_DEBUG ?= 1

CC=gcc

common_src :=$(wildcard ../*.c)
common_src_nodir :=$(notdir $(common_src))
common_objs := $(common_src:%.c=%.o)
common_objs_objdir:=$(common_src_nodir:%.c=objs/%.o)

src := $(wildcard ./*.c)
src += $(wildcard ../*.c)
src_nodir :=$(notdir $(src))

objs := $(src:%.c=%.o)
objs_objdir := $(src_nodir:%.c=objs/%.o)

CFLAGS ?= -I./ -I../ -c
LDFAGS := -lm 

ifeq ($(strip $(CFG_DEBUG)),1)
	CFLAGS+=-DDEBUG -g
	LDFAGS := -lm -g
endif

TARGET:=read_share_mem write_share_mem



.PHONY: all clean $(TARGET)

all:$(TARGET)

$(TARGET):$(objs)
	@echo "[LD $(notdir objs)==>$@]"
	$(Q)$(CC) $(common_objs_objdir)  $(addsuffix .o, objs/$@) $(LDFAGS) -o $@

$(filter %.o,$(objs)):%.o:%.c
	@echo "[CC $(notdir $^)]"
	$(Q)$(CC) $(CFLAGS) $< -o objs/$(notdir $@)
	
#clean the object file
clean:
	-rm -rf *.o objs/*.o $(TARGET)
